package ao

import (
	"context"
	pb "gitee.com/micro-services/protocol/room/server"
	"micro.room.server/impl"
)

type RoomDeviceController struct{}

func (rc *RoomDeviceController) CreateRoomDevice(ctx context.Context, r *pb.CreateRoomDeviceReq, w *pb.CreateRoomDeviceRsp) error {
	rsp, err := impl.CreateRoomDevice(ctx, r)
	if err != nil {
		return err
	}

	w.Msg = rsp.Msg
	w.RetCode = rsp.RetCode
	return nil
}

func (rc *RoomDeviceController) UpdateRoomDeviceInfo(ctx context.Context, r *pb.UpdateRoomDeviceInfoReq, w *pb.UpdateRoomDeviceInfoRsp) error {
	rsp, err := impl.UpdateRoomDeviceInfo(ctx, r)
	if err != nil {
		return err
	}

	w.Msg = rsp.Msg
	w.RetCode = rsp.RetCode
	return nil
}

func (rc *RoomDeviceController) DeleteRoomDevice(ctx context.Context, r *pb.DeleteRoomDeviceReq, w *pb.DeleteRoomDeviceRsp) error {
	rsp, err := impl.DeleteRoomDevice(ctx, r)
	if err != nil {
		return err
	}

	w.Msg = rsp.Msg
	w.RetCode = rsp.RetCode
	return nil
}

func (rc *RoomDeviceController) SearchRoomDevice(ctx context.Context, r *pb.SearchRoomDeviceReq, w *pb.SearchRoomDeviceRsp) error {
	info, count, err := impl.SearchRoomDevice(ctx, r)
	if err != nil {
		return err
	}

	w.List = info
	w.Count = count
	return nil
}

func (rc *RoomDeviceController) DeviceList(ctx context.Context, r *pb.DeviceListReq, w *pb.DeviceListRsp) error {
	return nil
}
